$(document).ready(function(){
	$("#name").blur(function(){
		doAjax();
	});
	$("#address").blur(function(){
		doAjax();
	});
	$("#tel").blur(function(){
		doAjax();
	});
	function doAjax(){
		var name = $("#name").val();
		var address = $("#address").val();
		var tel = $("#tel").val();
		$.ajax({
			type:"POST",
			url:"add_cor.php?cmd=ajaxSearch&name="+name+"&address="+address+"&tel="+tel,
			dataType:"json",
			success:function(msg){
				if(msg == "noFind"){
					$(".relate_cor em").html("您要添加的企业还未收录！添加成功后，您将有权对其更新、维护和管理！");
					$(".relate_cor ul").hide();
					$(".relate_cor").show();
				}else{
					var reArr = eval(msg);
					ReAjax(reArr);
				}
			}            
		 });
	}
	function ReAjax(reArr){
		$(".relate_cor em").html("您要添加的企业是不是：");
		$(".relate_cor").show();
		$(".relate_cor ul").show();
		var html_str = "";
		for(i=0;i<reArr.length;i++){
			var info = reArr[i].split("#|#");
			var cor_id = info[0];
			var cor_name = info[1];
			html_str += '<li><a href="/corporation/'+cor_id+'.html">'+cor_name+'</a></li>';
		}
		$(".relate_cor ul").html(html_str);
		$(".relate_cor ul li").mouseover(function(){
			$(this).addClass('li_hover');
		}).mouseout(function(){
			$(this).removeClass();
		});
	}
	$(".relate_cor ul li").mouseover(function(){
		$(this).addClass('li_hover');
	}).mouseout(function(){
		$(this).removeClass();
	});
	$("#click_check").click(function(){
		doAjax();
	});
	
});
function corCheck(e){
	if(!isLogin()){
		go_to_login(e);
		return false;
	}
	$("td:contains('*')").next().find("input").each(function(){ 
		if(this.value == '') { 
		text = $(this).parent().prev().text(); 
		alert(text+"是必填项"); 
		this.focus(); 
		document.execCommand("stop");
		} 
	});

	if($("#district_id").val() <= 0){
		alert("请选择区域！"); 
		this.focus(); 
		return false;
	}
	if($("td textarea").val() == ''){
		alert("企业介绍*：是必填项"); 
		this.focus(); 
		return false;
	}
	if($("#email").val() != ''){
		var preg = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
		var email = $("#email").val();
		if(!preg.test(email)){
			alert('请正确输入email地址！');
			return false;
		}
	}
	if($("#tel").val() != ''){
		var preg = /^[0-9-]+$/;
		var tel = $("#tel").val();
		if(!preg.test(tel)){
			alert('请正确输入电话！');
			return false;
		}
	}
	if($("#fax").val() != ''){
		var preg = /^[0-9-]+$/;
		var fax = $("#fax").val();
		if(!preg.test(fax)){
			alert('请正确输入传真！');
			return false;
		}
	}

	if($("#word").val() != ''){
		var word = $("#word").val();
		$.ajax({
			type:"POST",
			url:"add_cor.php?cmd=checkWord&word="+word,
			success:function(msg){
				if(msg != 'ok'){
					alert("验证码错误！");
					return false;
				}else{
					document.cor_form.submit();
				}
			}            
		 });
	}


}